package com.kcht.sylyg08.service;

import com.kcht.adp.common.log.Logger;
import com.kcht.adp.pagination.Page;
import com.kcht.sylyg08.ctrl.vo.ManualReportVO;
import com.kcht.sylyg08.dao.ICommandPerDao;
import com.kcht.sylyg08.dao.IManualReportDao;
import com.kcht.sylyg08.dao.impl.CommandPerDao;
import com.kcht.sylyg08.dao.impl.CommandTempDao;
import com.kcht.sylyg08.service.model.Res;
import com.kcht.sylyg08.service.model.RtnCode;
import com.kcth.sylyg08.entity.CommandPer;
import com.kcth.sylyg08.entity.CommandTemp;
import com.kcth.sylyg08.entity.ManualReport;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
import java.util.List;
import java.util.Objects;

/**
 * @program: G08ProductionLine
 * @description
 * @author: X.Gao
 * @create: 2019-07-22 11:01
 **/

@RequestScoped
@Transactional()
public class ManualReportService {

    @Inject
    private Logger logger;

    @EJB
    private IManualReportDao manualReportDao;

    @EJB
    private ICommandPerDao commandPerDao;

    @Inject
    private ManualReportHandlerService manualReportHandlerService;

    //分页查询信息
    public Page<CommandPer, CommandPer> list(Page<CommandPer, CommandPer> page) {

        return commandPerDao.getPageListByJPQL("CommandPer.queryRecordList", page);

    }

    //手动上传操作
    public void singleReport(List<Integer> ids) {
        ids.forEach(id -> {
            CommandPer commandPer = commandPerDao.get(id.longValue());
            if (Objects.nonNull(commandPer)) {

                    manualReportHandlerService.reportToMes(commandPer);

            }
        });
    }

    //删除记录
    public void delete(List<Integer> ids) {
        ids.forEach(id -> {
            CommandPer commandPer = commandPerDao.get(id.longValue());
            if (Objects.nonNull(commandPer)) {

                commandPerDao.delete(commandPer.getId());

            }
        });
    }

}
